package com.xhl.doeverything.dozer;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import java.io.IOException;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;

@ConfigurationProperties(
        prefix = "dozer"
)
public class DozerProperties {
    private static final ResourcePatternResolver PATTERN_RESOLVER = new PathMatchingResourcePatternResolver();
    private String[] mappingFiles = new String[]{"classpath*:dozer/*.dozer.xml"};

    public DozerProperties() {
    }

    public String[] getMappingFiles() {
        return (String[])Arrays.copyOf(this.mappingFiles, this.mappingFiles.length);
    }

    public DozerProperties setMappingFiles(String[] mappingFiles) {
        this.mappingFiles = (String[])Arrays.copyOf(mappingFiles, mappingFiles.length);
        return this;
    }

    public Resource[] resolveMapperLocations() {
        return (Resource[])Stream.of((String[])Optional.ofNullable(this.mappingFiles).orElse(new String[0])).flatMap((location) -> {
            return Stream.of(this.getResources(location));
        }).toArray((var0) -> {
            return new Resource[var0];
        });
    }

    private Resource[] getResources(String location) {
        try {
            return PATTERN_RESOLVER.getResources(location);
        } catch (IOException var3) {
            return new Resource[0];
        }
    }
}
